package cn.itcast.p2p20.act;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;

import cn.itcast.p2p20.R;
import cn.itcast.p2p20.utils.Util;

public class WelcomeActivity extends BaseActivity implements Animation.AnimationListener {

    private View imageView;
    private View imageViewBlur;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        imageView = findViewById(R.id.imageview);
        imageViewBlur = findViewById(R.id.imageview_blur);

        ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setDuration(2000);
        scaleAnimation.setFillAfter(true);
        scaleAnimation.setAnimationListener(this);
        imageView.startAnimation(scaleAnimation);

    }


    @Override
    public void onAnimationStart(Animation animation) {

    }

    //当缩放执行完毕，显示模糊图片
    @Override
    public void onAnimationEnd(Animation animation) {

        imageViewBlur.setVisibility(View.VISIBLE);
        imageViewBlur.setScaleX(1.2f);
        imageViewBlur.setScaleY(1.2f);

        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
        alphaAnimation.setDuration(1000);
        alphaAnimation.setFillAfter(true);

        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

                Intent intent = new Intent();
                if (Util.isStartGuideToMainUI(getApplicationContext())) {

                    intent.setClass(getApplicationContext(), MainActivity.class);
                } else {

                    intent.setClass(getApplicationContext(), GuideActivity.class);
                }
                startActivity(intent);
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        imageViewBlur.startAnimation(alphaAnimation);

    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
}
